import requests
import json
from base.config.service_config import BaiduFaceVerify

class FaceVerify:
    def __init__(self) -> None:
        self.token_url = BaiduFaceVerify.ACCESS_TOKEN_URL
        self.API_KEY = BaiduFaceVerify.API_KEY
        self.SECRET_KEY = BaiduFaceVerify.SECRET_KEY

    def main(self):
            
        url = "https://aip.baidubce.com/rpc/2.0/brain/solution/faceprint/verifyToken/generate?access_token=" + get_access_token()
        
        payload = json.dumps("")
        headers = {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
        
        response = requests.request("POST", url, headers=headers, data=payload)
        
        print(response.text)
    

    def get_access_token(cls):
        """
        使用 AK，SK 生成鉴权签名（Access Token）
        :return: access_token，或是None(如果错误)
        """
        
        params = {"grant_type": "client_credentials", "client_id": cls.API_KEY, "client_secret": cls.SECRET_KEY}
        return str(requests.post(url, params=params).json().get("access_token"))

if __name__ == '__main__':
    main()
